[...] printf("Enter name: \n"); if (fgets(name, sizeof name, stdin)) { fputs(name,fileptr); fclose(fileptr); printf("File write was successful\n"); } else { printf("Read error.\n"); }